#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
using namespace std;

int main()
{
	int n, m;
	for (;;) {
		cin >> n;
                if(n == 0){
                        break;
                }
                cin >> m;
		vector<int> buket(n + 1, 0), left(n + 1, 0), right(n + 1, 0);
		vector<int> log2(n + 1, 0);

		int cnt = 0;
		for (int i = 1, pre = INT32_MAX, cur; i <= n; i++) {
			cin >> cur;
			if (cur != pre) {
				right[cnt] = i - 1;
				left[++cnt] = i;
			}
			buket[i] = cnt;
			pre = cur;
		}
		right[cnt] = n;
		log2[0] = -1;
		int power = std::log2(cnt);
		vector<vector<int>> stmax(cnt + 1, vector<int>(power + 1, 0));
		for (int i = 1; i <= cnt; i++) {
			log2[i] = log2[i >> 1] + 1;
			stmax[i][0] = right[i] - left[i] + 1;
		}
		for (int p = 1; p <= log2[cnt]; p++) {
			for (int i = 1; i <= cnt - (1 << p) + 1; i++) {
				stmax[i][p] = max(stmax[i][p - 1], stmax[i + (1 << p - 1)][p - 1]);
			}
		}

		for (int i = 0, p, l, r; i < m; i++) {
			cin >> l >> r;
			if (r < l) {
				swap(l, r);
			}

			int lbk = buket[l];
			int rbk = buket[r];
			if (lbk == rbk) {
				cout << r - l + 1 << endl;
				continue;
			}

			int lmax = right[lbk] - l + 1;
			int rmax = r - left[rbk] + 1;
			int mmax = 0;
			if (lbk + 1 < rbk) {
				lbk++;
				rbk--;
				p = log2[rbk - lbk + 1];
				mmax = max(stmax[lbk][p], stmax[rbk - (1 << p) + 1][p]);
			}
			cout << max({ lmax, mmax, rmax }) << endl;
		}
	}

	return 0;
}